﻿using Abp.Authorization;
using Abp.Localization;
using Abp.MultiTenancy;

namespace Partner.Surround.Authorization
{
    public class SurroundAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            #region 顶级权限
            var pages = context.CreatePermission(PermissionNames.Pages, L("Pages"));
            #endregion

            #region 系统功能
            var frame = pages.CreateChildPermission(PermissionNames.Pages_Frame, L("Frame"));

            #region 组织机构
            var organizationUnits = frame.CreateChildPermission(PermissionNames.Pages_Frame_OrganizationUnits, L("OrganizationUnits"));
            organizationUnits.CreateChildPermission(PermissionNames.Pages_Frame_OrganizationUnits_Create, L("CreateOrganizationUnit"));
            organizationUnits.CreateChildPermission(PermissionNames.Pages_Frame_OrganizationUnits_Update, L("EditOrganizationUnit"));
            organizationUnits.CreateChildPermission(PermissionNames.Pages_Frame_OrganizationUnits_Delete, L("DeleteOrganizationUnit"));
            #endregion

            #region 用户管理
            var users = frame.CreateChildPermission(PermissionNames.Pages_Frame_Users, L("Users"));
            users.CreateChildPermission(PermissionNames.Pages_Frame_Users_Create, L("CreateUser"));
            users.CreateChildPermission(PermissionNames.Pages_Frame_Users_Update, L("UpdateUser"));
            users.CreateChildPermission(PermissionNames.Pages_Frame_Users_Delete, L("DeleteUser"));
            users.CreateChildPermission(PermissionNames.Pages_Frame_Users_ResetPassword, L("ResetPassword"));
            #endregion

            #region 角色管理
            var roles = frame.CreateChildPermission(PermissionNames.Pages_Frame_Roles, L("Roles"));
            roles.CreateChildPermission(PermissionNames.Pages_Frame_Roles_Create, L("CreateRole"));
            roles.CreateChildPermission(PermissionNames.Pages_Frame_Roles_Update, L("UpdateRole"));
            roles.CreateChildPermission(PermissionNames.Pages_Frame_Roles_Delete, L("DeleteRole"));
            #endregion

            #region 权限管理
            var permissions = frame.CreateChildPermission(PermissionNames.Pages_Frame_Permissions, L("Permissions"));
            #endregion

            #region 审计日志
            var auditLogs = frame.CreateChildPermission(PermissionNames.Pages_Frame_AuditLogs, L("AuditLogs"));
            #endregion

            #region 系统设置
            var hostSettings = frame.CreateChildPermission(PermissionNames.Pages_Frame_HostSettings, L("HostSettings"));
            #endregion

            #region 系统维护
            var maintenances = frame.CreateChildPermission(PermissionNames.Pages_Frame_Maintenance, L("Maintenance"));

            #region 系统日志
            var logs = frame.CreateChildPermission(PermissionNames.Pages_Frame_Maintenance_Logs, L("SystemLogs"));
            logs.CreateChildPermission(PermissionNames.Pages_Frame_Maintenance_Logs_DownLoad, L("DownLoadLogs"));
            logs.CreateChildPermission(PermissionNames.Pages_Frame_Maintenance_Logs_Refresh, L("RefreshLogs"));
            #endregion

            #region 版本管理
            var editions = frame.CreateChildPermission(PermissionNames.Pages_Frame_Editions, L("Editions"), multiTenancySides: MultiTenancySides.Host);
            editions.CreateChildPermission(PermissionNames.Pages_Frame_Editions_Create, L("CreateEdition"), multiTenancySides: MultiTenancySides.Host);
            editions.CreateChildPermission(PermissionNames.Pages_Frame_Editions_Update, L("UpdateEdition"), multiTenancySides: MultiTenancySides.Host);
            editions.CreateChildPermission(PermissionNames.Pages_Frame_Editions_Delete, L("DeleteEdition"), multiTenancySides: MultiTenancySides.Host);
            editions.CreateChildPermission(PermissionNames.Pages_Frame_Editions_MoveTenantsToAnotherEdition, L("MoveTenantsToAnotherEdition"), multiTenancySides: MultiTenancySides.Host);
            #endregion

            #region 租户管理
            var tenants = frame.CreateChildPermission(PermissionNames.Pages_Frame_Tenants, L("Tenants"), multiTenancySides: MultiTenancySides.Host);
            tenants.CreateChildPermission(PermissionNames.Pages_Frame_Tenants_MoveTenantToAnotherEdition, L("MoveTenantsToAnotherEdition"), multiTenancySides: MultiTenancySides.Host);
            #endregion

            #endregion

            #endregion

            #region 资源管理
            var baseManages = pages.CreateChildPermission(PermissionNames.Pages_Base, L("BaseManage"));

            #region 数据字典
            var datadictionaries = baseManages.CreateChildPermission(PermissionNames.Pages_Base_DataDictionary, L("DataDictionary"));
            datadictionaries.CreateChildPermission(PermissionNames.Pages_Base_DataDictionary_Create, L("CreateDataDictionary"));
            datadictionaries.CreateChildPermission(PermissionNames.Pages_Base_DataDictionary_Update, L("UpdateDataDictionary"));
            datadictionaries.CreateChildPermission(PermissionNames.Pages_Base_DataDictionary_Delete, L("DeleteDataDictionary"));

            #region 数据字典项
            var datadictionaryItems = datadictionaries.CreateChildPermission(PermissionNames.Pages_Base_DataDictionary_DataDictionaryItem, L("DataDictionaryItem"));
            datadictionaryItems.CreateChildPermission(PermissionNames.Pages_Base_DataDictionary_DataDictionaryItem_Create, L("CreateDataDictionaryItem"));
            datadictionaryItems.CreateChildPermission(PermissionNames.Pages_Base_DataDictionary_DataDictionaryItem_Update, L("UpdateDataDictionaryItem"));
            datadictionaryItems.CreateChildPermission(PermissionNames.Pages_Base_DataDictionary_DataDictionaryItem_Delete, L("DeleteDataDictionaryItem"));
            #endregion

            #endregion

            #endregion

            #region A业务模块
            pages.CreateChildPermission(PermissionNames.Pages_TaskManage, L("TaskManage"));
            #endregion

            #region B业务模块

            #endregion

            #region N业务模块

            #endregion
        }

        private static ILocalizableString L(string name)
        {
            return new LocalizableString(name, SurroundConsts.LocalizationSourceName);
        }
    }
}
